/*
 * trace_VariableBlock.c
 *
 *  Created on: 2012/07/10
 *      Author: guanxiaoying
 */

#include "../table.h"
#include "../trace_cmd_table.h"
typedef struct _TRVARIABLEBLOCK
{
	U4 size;
	U4 flag;
	AST astFirst;
	AST astLast;
} TRVARIABLEBLOCK, *PTRVARIABLEBLOCK;

#define TableSize  (sizeof(TRVARIABLEBLOCK ))
#define TableType  PTRVARIABLEBLOCK
#define stTable stTrVariBlockManager.memoryBlocks
#define maxTable stTrVariBlockManager.maxRecordNum
#define  maxNumPerBlk  (stTrVariBlockManager.astMaxNum_Block)


static TABLEMANAGER stTrVariBlockManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};
static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stTrVariBlockManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}
}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stTrVariBlockManager, resetListener,  index );
	if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
}
static BOOL ClearTable( VOID )
{
	return Clear_Com( &stTrVariBlockManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stTrVariBlockManager, astReqArg, resetListener );
}
static AST getMaxLineNum( VOID ){
	return maxTable;
}
static U4 getSize( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->size;
}
static U4 setSize( AST astIndex, U4 value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->size=value;
}
static U4 getFlag( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->flag;
}
static U4 setFlag( AST astIndex, U4 value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->flag=value;
}
static AST getBegin( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astFirst;
}
static AST setBegin( AST astIndex, AST value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astFirst=value;
}
static AST getEnd( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astLast;
}
static AST setEnd( AST astIndex, AST value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astLast=value;
}

const TRVARIABLEBLOCKACCESS stTrVariableBlockAccess={
		ClearTable,
		AllocTable,
		getMaxLineNum,
		{
				getBegin,
				setBegin
		},
		{
				getEnd,
				setEnd
		},
		{
				getSize,
				setSize
		},
		{
				getFlag,
				setFlag
		}
};




